import { CommonModal } from "@/views/components/CommonModal";
import SubTitle from "@/pages/OrderModule/common/components/SubTitle";
import { DialogEnum } from "../index";
import { SelectBatchInput } from "@/pages/OrderModule/orderList/components/Filter/components/SelectBatchInput";
import { Alert, Input, message, Select, AutoComplete, Button, Cascader, Col, DatePicker, InputNumber } from "antd";
import FieldWrapper from "@/pages/OrderModule/orderList/components/Filter/components/FieldWrapper";
import { useState } from "react";
import { cloneDeep } from "lodash";

const Options = [
	{
		value: "1",
		label: "统一改为"
	},
	{
		value: "2",
		label: "统一上调"
	},
	{
		value: "3",
		label: "统一下调"
	}
];

const BatchModifyQuantity = ({ selectedRows = [], updateDataSource, dataSource, actionName, onCancel }) => {
	const [value, setValue] = useState("1");
	const [num, setNum] = useState();
	const handleOk = () => {
		const ids = selectedRows.map(e => e.uuid);
		console.log("dataSource", dataSource);
		const list = cloneDeep(dataSource);
		list.forEach(e => {
			if (ids.includes(e.uuid)) {
				switch (value) {
					case "1":
						e.actualNum = num;
						break;
					case "2":
						e.actualNum = num + e.actualNum;
						break;
					case "3":
						e.actualNum = e.actualNum - num < 0 ? 0 : e.actualNum - num;
						break;
				}
			}
		});
		message.success("操作成功");
		onCancel();
		updateDataSource(list);
	};
	return (
		<CommonModal
			title={{ title: "批量修改数量" }}
			open={Boolean(actionName === DialogEnum.BatchModifyQuantity)}
			width="553px"
			onOk={handleOk}
			onCancel={onCancel}
		>
			<Alert type="info" showIcon style={{ marginBottom: "24px" }} message="注：若批量修改后商品数值小于0，按照0来填写数值" />
			<SubTitle
				title={
					<div style={{ lineHeight: "21px" }}>
						<span>批量修改详情</span>
					</div>
				}
				as="s2"
				symbol
			/>
			<p style={{ margin: "12px 0" }}>商品种类数：{new Set(selectedRows.map(e => e.skuCode)).size}</p>
			<Input.Group compact>
				<Select
					value={value}
					placeholder="物流状态"
					options={Options}
					size="middle"
					onChange={v => {
						console.log(v);
						setValue(v);
					}}
					style={{
						width: "20%"
					}}
				/>
				<InputNumber
					value={num}
					placeholder="请输入"
					controls={false}
					precision={0}
					min={0}
					size="middle"
					onChange={v => {
						setNum(v);
					}}
					style={{
						width: "80%"
					}}
				/>
			</Input.Group>
			{/* <SelectBatchInput
				value={value}
				options={Options}
				defaultSelectValue="1"
				placeholder="请输入"
				allowclear="true"
				isBatchInput={false}
				onChange={v => {
					console.log(v);
					setValue(v);
				}}
			/> */}
			<div style={{ height: 24 }} />
		</CommonModal>
	);
};
export default BatchModifyQuantity;
